package com.example.service.impl;

import com.example.dao.PermDao;
import com.example.entity.Perm;
import com.example.service.PermService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author fyxw
 */
@Service
public class PermServiceImpl implements PermService {
    @Resource
    private PermDao mapper;

    @Override
    public void addPerm(Perm perm) {
        mapper.addPerm(perm);
    }

    @Override
    public Perm findPermById(int id) {
        return mapper.findPermById(id);
    }

    @Override
    public boolean deletePerm(int id) {
        return mapper.deleteById(id) != 0;
    }

    @Override
    @Transactional(rollbackFor = Throwable.class)
    public boolean updatePerm(Perm perm) {
        if (mapper.findPermById(perm.getId()) != null) {
            mapper.updatePerm(perm);
            return true;
        }
        return false;
    }

    @Override
    public List<Perm> findAll() {
        return mapper.findAll();
    }
}
